Skip to content

Conversation

stevensJourney
Copy link
Collaborator

Overview

#136 Moved common MongoDB logic to the @powersync/lib-service-mongodb package.

The bucket storage module's MongoDB connection is created using a utility from the shared library. The storage implementation checks certain caught Errors if they are instances of the MongoDB MongoServerError class. The instanceof checks fail if the shared library and the storage module use different versions of the MongoDB package. The core repository uses the same version throughout, but the hosted version's lockfile resolved different versions which caused the error detection to fail. Luckily the affected processes are retried, which did not cause any major issues.

This PR addresses the issue via two methods.

A isMongoServerError utility function is now exported from @powersync/lib-service-mongodb. The instanceof check in this function should pass if the connection was created from the shared library. Additionally a fallback check is added by checking the Error prototype name field - this should detect the error type even if a different MongoDB package spawned the connection or error.

The direct mongodb NPM package dependency has been removed from the MongoDB replicator and storage modules. The shared MongoDB library now re-exports it's mongodb dependency.

Testing

Development packages were released and locally installed in the hosted repository. A sync rule change was applied which triggered the termination of previous sync rules. Sync rules were correctly terminated with no error logs.

Before:
image

After:
image

The MongoDB replicator was also smoke tested locally.

Copy link

changeset-bot bot commented Jan 10, 2025

🦋 Changeset detected

Latest commit: 227aefb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@powersync/service-module-mongodb-storage Minor
@powersync/service-module-mongodb Minor
@powersync/lib-service-mongodb Minor
@powersync/service-image Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@stevensJourney stevensJourney marked this pull request as ready for review January 10, 2025 12:45
@stevensJourney stevensJourney merged commit 9709b2d into main Jan 10, 2025
16 checks passed
@stevensJourney stevensJourney deleted the fix/multiple-mongodb branch January 10, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants